package com.buaa.student.controller;

import com.buaa.student.pojo.Student;
import com.buaa.student.service.DakaService;
import com.buaa.student.service.StudentQueryService;
import com.buaa.student.vo.DNDakaStudent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.sql.Date;
import java.util.ArrayList;

@Controller
public class DakaStatController {

    @Autowired
    private StudentQueryService studentQueryService;

    @Autowired
    private DakaService dakaService;

    @GetMapping("/daka/query")
    public String QueryStudentByKey(@RequestParam("key") String key, Model model){

        String newKey = '%'+key+'%';
        ArrayList<Student> students = studentQueryService.QueryByKey(newKey);
        model.addAttribute("students_dengji",students);

        return "index";
    }

    @GetMapping("/daka/submit")
    public String submitRecord(@RequestParam("xingming") String xingming,
                               @RequestParam("xuehao") String xuehao,
                               Model model){

        int addRecord = dakaService.addRecord(xingming, xuehao, new Date(System.currentTimeMillis()));
        System.out.println("addRecord："+addRecord);
        model.addAttribute("message","成功添加");

        return "index";
    }

    @GetMapping("/data/list")
    public String getDidNotDakaList(Model model){

        Date date = new Date(System.currentTimeMillis());

        ArrayList<DNDakaStudent> DNDakaStudentList3Times = dakaService.getNewWeiDakaList(date,3,4);
        model.addAttribute("DNDakaStudentList3Times",DNDakaStudentList3Times);

        ArrayList<DNDakaStudent> DNDakaStudentList4Times = dakaService.getNewWeiDakaList(date,4,1000);
        model.addAttribute("DNDakaStudentList4Times",DNDakaStudentList4Times);

        return "weidakalist";
    }

}
